package com.yunhai.device.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunhai.common.dto.GlobalException;
import com.yunhai.common.dto.PaginationVo;
import com.yunhai.common.utils.ObjectUtil;
import com.yunhai.common.utils.ReflectionCopy;
import com.yunhai.device.mapper.OrrOutcupEfficiencySummaryMapper;
import com.yunhai.device.service.OrrOutcupEfficiencySummaryService;
import com.yunhai.model.entity.orr.OrrOutcupEfficiencySummaryEntity;
import com.yunhai.model.vo.orr.OrrOutcupEfficiencySummaryQuery;
import com.yunhai.model.vo.orr.OrrOutcupEfficiencySummaryVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OrrOutcupEfficiencySummaryServiceImpl implements OrrOutcupEfficiencySummaryService {

    @Resource
    private OrrOutcupEfficiencySummaryMapper orrOutcupEfficiencySummaryMapper;

    /**
     * 获取 OrrOutcupEfficiencySummary 分页列表
     */
    @Transactional
    public IPage getOrrOutcupEfficiencySummaryPagination(PaginationVo paginationVo, OrrOutcupEfficiencySummaryQuery orrOutcupEfficiencySummaryQuery ) throws Exception {

        IPage page = new Page( paginationVo.getPageIndex(), paginationVo.getPageSize() );
        LambdaQueryWrapper<OrrOutcupEfficiencySummaryEntity> lqs = new LambdaQueryWrapper();
        orrOutcupEfficiencySummaryMapper.selectPage(page, lqs);

        List<OrrOutcupEfficiencySummaryEntity> record = page.getRecords();
        if( !ObjectUtil.isNotEmptyList(record)){
            return page;
        }
        return page;
    }


    /**
     * 获取 OrrOutcupEfficiencySummary 所有数据
     *
     */
    @Transactional
    public List<OrrOutcupEfficiencySummaryEntity> getOrrOutcupEfficiencySummaryAllList( OrrOutcupEfficiencySummaryQuery orrOutcupEfficiencySummaryQuery ) throws Exception {

        LambdaQueryWrapper<OrrOutcupEfficiencySummaryEntity> lqs = new LambdaQueryWrapper();
        List<OrrOutcupEfficiencySummaryEntity> list = orrOutcupEfficiencySummaryMapper.selectList(lqs);
        return list;
    }


    /**
     * 获取 OrrOutcupEfficiencySummary 详情
     */
    @Transactional
    public OrrOutcupEfficiencySummaryEntity getOrrOutcupEfficiencySummaryDetail( Long id) throws Exception {

        OrrOutcupEfficiencySummaryEntity orrOutcupEfficiencySummaryEntity = orrOutcupEfficiencySummaryMapper.selectById(id);
        return orrOutcupEfficiencySummaryEntity;
    }


    /**
     * 新增 OrrOutcupEfficiencySummary
     * */
    @Transactional
    public void addOrrOutcupEfficiencySummary(OrrOutcupEfficiencySummaryVo orrOutcupEfficiencySummaryVo) throws Exception {

        OrrOutcupEfficiencySummaryEntity orrOutcupEfficiencySummaryEntity = new OrrOutcupEfficiencySummaryEntity();
        ReflectionCopy.copyProperties( orrOutcupEfficiencySummaryEntity, orrOutcupEfficiencySummaryVo );
        orrOutcupEfficiencySummaryMapper.insert(orrOutcupEfficiencySummaryEntity);
        return;
    }


    /**
     * 更新 OrrOutcupEfficiencySummary
     * */
    @Transactional
    public void updateOrrOutcupEfficiencySummary( OrrOutcupEfficiencySummaryVo orrOutcupEfficiencySummaryVo) throws Exception {

        if( orrOutcupEfficiencySummaryVo.getId() == null ){
            throw GlobalException.gen(10021, "id不存在");
        }
        OrrOutcupEfficiencySummaryEntity orrOutcupEfficiencySummaryEntity = new OrrOutcupEfficiencySummaryEntity();
        ReflectionCopy.copyProperties( orrOutcupEfficiencySummaryEntity, orrOutcupEfficiencySummaryVo );
        orrOutcupEfficiencySummaryMapper.updateById(orrOutcupEfficiencySummaryEntity);
        return;
    }

    /**
     * 删除 OrrOutcupEfficiencySummary
     * */
    @Transactional
    public void batchRemoveOrrOutcupEfficiencySummary( List<Long> ids ) throws Exception {

        if( !ObjectUtil.isNotEmptyList(ids) ){
            throw GlobalException.gen(10011, "要删除的id不存在");
        }
        orrOutcupEfficiencySummaryMapper.deleteBatchIds(ids);
    }

}